package makovo.ajax;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import makovo.data.Resources;
import makovo.entities.ApplicantDocReport;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class DocReport extends ActionSupport implements ServletRequestAware, SessionAware, Serializable {
	private static final long serialVersionUID = 1L;
	private HttpServletRequest mRequest;
	private Map<String, Object> mSession;
	private final int PAGE_SIZE = 50;

	public ArrayList<ApplicantDocReport> mDocReport = new ArrayList<>();
	public long mTotal = -1;

	public ArrayList<ApplicantDocReport> getDocs() {
		return mDocReport;
	}

	public long getTotal() {
		if (mTotal == -1)
			try {
				mTotal = Resources.getTotalApplicants();
			} catch (Exception e) {
				e.printStackTrace();
			}

		return mTotal;
	}

	public int getPageSize() {
		return PAGE_SIZE;
	}

	public String showDocs() {
		try {
			String par = this.mRequest.getParameter("pag");

			mDocReport = Resources.getDocReport(Integer.valueOf(par), PAGE_SIZE);

		} catch (Exception e) {
			return ActionSupport.ERROR;
		}

		return ActionSupport.SUCCESS;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.mRequest = request;
	}

	@Override
	public void setSession(Map<String, Object> sessionInfo) {
		this.mSession = sessionInfo;
	}

}
